<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>{$seo_title}</title>	  
	<meta name="keywords" content="{$keywords}" />
	<meta name="description" content="{$description}" />
	<link href="https://lib.baomitu.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	
</head>
<body>
    {m:include "index","tools_header"}
	<div class="container">
	  <div class="panel panel-default">
	    <div class="panel-heading">随机密码生成器</div>
	    <div class="panel-body tool-body">
	      <div class="form-group">
	        <label class="checkbox-inline">
	          <input type="checkbox" id="include_number" checked>数字
	        </label>
	        <label class="checkbox-inline">
	          <input type="checkbox" id="include_lowercaseletters" checked>小写字母
	        </label>
	        <label class="checkbox-inline">
	          <input type="checkbox" id="include_uppercaseletters" checked>大写字母
	        </label>
	        <label class="checkbox-inline">
	          <input type="checkbox" id="include_punctuation">标点符号
	        </label>
	        <label class="checkbox-inline">
	          <input type="checkbox" id="password_unique">字符不重复
	        </label>
	      </div>
	      <div class="form-group">
	        <div class="input-group">
	          <span class="input-group-addon">密码长度</span>
	          <input type="number" id="password_length" class="form-control" min="0" value="8">
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="input-group">
	          <span class="input-group-addon">密码数量</span>
	          <input type="number" id="password_quantity" class="form-control" min="0" value="5">
	        </div>
	      </div>
	      <div class="form-group text-center">
	        <button id="generate" class="btn btn-success">生成密码</button>
	      </div>
	      <textarea id="output" class="form-control" cols="40" rows="7" readonly></textarea>
	    </div>
	  </div>
	  <div class="panel panel-default">
	    <div class="panel-heading">工具简介</div>
	    <div class="panel-body">
	      <p>随机密码生成器 - 随机字符串生成器 - Random Password Generator。</p>
	      <p>可用于生成随机卡密等等</p>
	    </div>
	  </div>
	</div>
	<script>
		$includeNumber = document.getElementById("include_number"),
		$includeLowercaseletters = document.getElementById("include_lowercaseletters"),
		$includeUppercaseletters = document.getElementById("include_uppercaseletters"),
		$includePunctuation = document.getElementById("include_punctuation"),
		$passwordUnique = document.getElementById("password_unique"),
		$passwordLength = document.getElementById("password_length"),
		$passwordQuantity = document.getElementById("password_quantity"),
		$generate = document.getElementById("generate"),
		$output = document.getElementById("output");

		function rand(max) {
		    return Math.floor(Math.random() * max);
		};

		$generate.onclick = function() {
		    var chars = "";

		    if ($includeNumber.checked) chars += "0123456789";
		    if ($includeLowercaseletters.checked) chars += "abcdefghijklmnopqrstuvwxyz";
		    if ($includeUppercaseletters.checked) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		    if ($includePunctuation.checked) chars += "`~!@#$%^&*()-_=+[{]}\|;:'\",<.>/?";

		    var passwords = [],
		    passwordUnique = $passwordUnique.checked;
		    for (var i = 0,
		    l = $passwordQuantity.value; i < l; i++) {
		        var _chars = chars.split(""),
		        password = "";
		        for (var j = 0,
		        k = $passwordLength.value; j < k; j++) {
		            if (_chars.length < 1) break;
		            var index = rand(_chars.length);
		            password += _chars[index];
		            if (passwordUnique) _chars.splice(index, 1);
		        };
		        passwords.push(password);
		    };
		    $output.value = passwords.join("\n");
		};

		$output.onfocus = function() {
		    this.select();
		}
	</script>
</body>
</html>